package cn.group.hotel2.controller;

import cn.group.hotel2.pojo.dto.RoomCheckOutAddNewDTO;
import cn.group.hotel2.pojo.dto.RoomCheckOutUpdateDTO;
import cn.group.hotel2.pojo.vo.RoomCheckOutListCountVO;
import cn.group.hotel2.pojo.vo.RoomCheckOutListItemVO;
import cn.group.hotel2.pojo.vo.RoomCheckOutStandardVO;
import cn.group.hotel2.service.IRoomCheckOutService;
import cn.group.hotel2.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 处理退房登记相关请求的控制器
 * 
 * @author wcl
 * @version 0.0.1
 * @date 2022/11/25
 */
@Slf4j
@Valid
@RestController
@RequestMapping("/checkOut")
@Api(tags = "02 退房登记管理模块")
public class RoomCheckOutController {
    
    @Autowired
    private IRoomCheckOutService roomCheckOutService;

    public RoomCheckOutController() {
        log.debug("创建控制器对象：RoomCheckOutController");
    }

    @ApiOperation("新增退房登记")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Valid RoomCheckOutAddNewDTO roomCheckOutAddNewDTO) {
        log.debug("开始处理【新增退房登记】的请求，参数：{}", roomCheckOutAddNewDTO);
        roomCheckOutService.addNew(roomCheckOutAddNewDTO);
        log.debug("新增退房登记成功！");
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除退房登记")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name="id",value = "退房登记id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> deleteById(@Range(min = 1,message = "删除退房登记失败,请填写有效的大于0的id") @PathVariable Long id) {
        log.debug("开始处理【根据id删除退房登记】的请求,参数:{}", id);
        roomCheckOutService.deleteById(id);
        log.debug("删除退房登记成功!");
        return JsonResult.ok();
    }

    @ApiOperation("根据退房登记id修改退房登记详情")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name="id",value = "退房登记id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> update(@PathVariable Long id, RoomCheckOutUpdateDTO roomCheckOutUpdateDTO) {
        log.debug("开始处理【根据退房登记id修改退房登记详情】的请求,id参数:{},数据参数:{}", id, roomCheckOutUpdateDTO);
        roomCheckOutService.updateById(id, roomCheckOutUpdateDTO);
        log.debug("修改数据成功!");
        return JsonResult.ok();
    }

    @ApiOperation("根据id查询退房登记详情")
    @ApiOperationSupport(order = 405)
    @GetMapping("/{id:[0-9]+}/getStandardById")
    @ApiImplicitParam(name = "id", value = "退房登记id", required = true, dataType = "long")
    public JsonResult<RoomCheckOutStandardVO> getStandardById(@Range(min = 1, message = "查询退房登记详情失败,请填写有效的大于0的id") @PathVariable Long id){
        log.debug("开始处理【根据id查询退房登记详情】请求,参数:{}", id);
        RoomCheckOutStandardVO queryResult = roomCheckOutService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }

    @ApiOperation("查询退房登记列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("")
    public JsonResult<List<RoomCheckOutListItemVO>> list(){
        log.debug("开始处理【查询退房登记列表】请求,无参数");
        List<RoomCheckOutListItemVO> list = roomCheckOutService.list();
        return JsonResult.ok(list);
    }

    @ApiOperation("根据所选的页数来分页查询")
    @ApiOperationSupport(order = 411)
    @ApiImplicitParam(name="pageNum",value = "需要跳过的记录数",required = true,dataType = "long")
    @GetMapping("/listByPageNum")
    public JsonResult<List<RoomCheckOutListItemVO>> listByPageNum(@Range(min = 1,message = "查询退房登记失败,请填写有效的大于0的页数")
                                                                         Long pageNum) {
        log.debug("开始处理【根据所选的页数来分页查询】的请求,参数:{}", pageNum);
        List<RoomCheckOutListItemVO> list = roomCheckOutService.listByPageNum(pageNum);
        return JsonResult.ok(list);
    }

    @ApiOperation("查询列表所有的数据以统计其数量")
    @ApiOperationSupport(order = 450)
    @GetMapping("/count")
    public JsonResult<List<RoomCheckOutListCountVO>> listCount(){
        log.debug("开始处理【查询列表所有的数据以统计其数量】请求,无参数");
        List<RoomCheckOutListCountVO> list = roomCheckOutService.listCount();
        return JsonResult.ok(list);
    }
}
